package com.example.meterialproject.activitys.transition.demo2

import android.content.Intent
import android.os.Bundle
import androidx.core.app.ActivityOptionsCompat
import androidx.recyclerview.widget.RecyclerView
import com.example.meterialproject.R
import com.example.meterialproject.base.BaseActivity
import com.example.meterialproject.databinding.LayoutRecyclerViewBinding
import com.example.meterialproject.exts.createRecyclerView

/**
 *
 * @ClassName: TransitionDemoForm2Activity
 * @Author: android 超级兵
 * @CreateDate: 4/27/22$ 10:24 AM$
 * TODO
 */
class TransitionDemoForm2Activity : BaseActivity<LayoutRecyclerViewBinding>() {
//class TransitionDemoForm2Activity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // 进场动画
        overridePendingTransition(R.anim.enter_in, R.anim.exit_in)


        findViewById<RecyclerView>(R.id.recycler_view).createRecyclerView(this, 1) { view, url, _ ->

            val bundle =
                ActivityOptionsCompat.makeSceneTransitionAnimation(this,
                    view, url).toBundle()


            // A --> B
//            val bundle = ActivityOptionsCompat.makeCustomAnimation(
//                this,
//                R.anim.translate_enter, // A 页面进入动画
//                R.anim.translate_exit, // B页面退出动画
//            ).toBundle()

//            val bundle =
//                ActivityOptionsCompat.makeScaleUpAnimation(
//                    view,
//                    0, 0, 400, 100
//                ).toBundle()


            Intent(this, TransitionDemoTo2Activity::class.java).apply {
                putExtra(TransitionDemoTo2Activity.TRANSITION_NAME, url)
            }.also {
                startActivity(it, bundle)
            }
        }
    }

    override fun finish() {
        super.finish()
        // 退出动画
        overridePendingTransition(R.anim.enter_out, R.anim.exit_out)
    }
}